#pragma once

#include <QObject>
#include <QTcpSocket>
#include <QByteArray>
#include <QString>
#include <QTimer>
#include <QVariantMap>

using namespace std;


class TcpClient : public QObject
{
    Q_OBJECT
public:
    TcpClient();
    ~TcpClient();

public:
    void init(const string& groupID,const string &ip,const int &port);
    Q_INVOKABLE bool start();
    Q_INVOKABLE void stop();

private:
    void write(const QByteArray& msg);

//对外接口
public slots:
    void slot_write(const QString& msg);//发送数据
    void slot_start();

//内部使用的
private slots:
    void slot_read();

signals:
    void signal_openStatus(const QVariantMap&);//串口是否打开成功的信号 
    void signal_tcpClient(const QVariantMap& msg);

private:
    string groupID_;
    string ip_;
    int port_;
    QTcpSocket *cSocket_ = nullptr;
    bool isConnected_ = false;
    QByteArray rec_buffer_;
};



